const fs = require('fs')
const path = require('path')

const updateFile = (req, res) => {
  try {
    // req.file 是由multer处理后的文件信息
    if (!req.file) {
      return res.status(400).send('No file uploaded.');
    }
    console.log(req.file);

    fs.rename(req.file.path, path.join(req.file.destination, req.file.originalname), (err) => {
      console.log(err);
    })

    res.send(`File uploaded successfully: ${req.file.originalname}`);
  } catch (err) {
    res.status(500).send(err);
  }
}

module.exports = {
  updateFile
}
